/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.*;

/**
 * @author USER
 */
public class NinjaRunMidlet extends MIDlet implements CommandListener {

    public static int CLICKED = 0;
    protected Display display;      //reference to display
    private Command cmdExit;
    //canvas
    private GrassCanvas grassCanvas;
    private DessertCanvas dessertCanvas;
    private SnowCanvas snowCanvas;
    private MenuCanvas menuCanvas;
    private HelpCanvas helpCanvas;
    private AboutCanvas aboutCanvas;

    public NinjaRunMidlet() {
        display = Display.getDisplay(this);

        // create game canvas and exit command
        /*
        if ((grassCanvas = new GrassCanvas(this)) != null) {
        //cmdExit = new Command("Exit", Command.EXIT, 0);
        //grassCanvas.addCommand(cmdExit);
        //grassCanvas.setCommandListener(this);
        }
         * 
         */

        aboutCanvas = new AboutCanvas(this, display);
        helpCanvas = new HelpCanvas(this, display);
        menuCanvas = new MenuCanvas(this, display);
    }

    public void startApp() {
        showMenuCanvas();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        menuCanvas.stop();
        if (grassCanvas != null) {
            grassCanvas.stop();
        }
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdExit) {
            destroyApp(true);
            notifyDestroyed();
        }
    }

    public void exit() {
        menuCanvas.stop();
        if (grassCanvas != null) {
            grassCanvas.stop();
        }
        destroyApp(true);
        notifyDestroyed();
    }

    public void showMenuCanvas() {
        CLICKED = 0;
        //menuCanvas.stop();
        if (grassCanvas != null) {
            grassCanvas.stop();
        }
        if (dessertCanvas != null) {
            dessertCanvas.stop();
        }
        if (snowCanvas != null) {
            snowCanvas.stop();
        }

        grassCanvas = null;
        dessertCanvas = null;
        snowCanvas = null;

        menuCanvas.start();
        display.setCurrent(menuCanvas);
    }

    public void showAboutCanvas() {
        menuCanvas.stop();
        if (grassCanvas != null) {
            grassCanvas.stop();
        }
        display.setCurrent(aboutCanvas);
    }

    public void showHelpCanvas() {
        menuCanvas.stop();
        if (grassCanvas != null) {
            grassCanvas.stop();
        }
        display.setCurrent(helpCanvas);
    }

    public void showGrassCanvas() {
        if (CLICKED < 1) {
            CLICKED = CLICKED + 1;
            grassCanvas = new GrassCanvas(this);
            menuCanvas.stop();
            grassCanvas.stop();
            if (grassCanvas != null) {
                display.setCurrent(grassCanvas);
                grassCanvas.start();
            }
        }
    }

    public void showDessertCanvas() {
        if (CLICKED < 1) {
            CLICKED = CLICKED + 1;
            dessertCanvas = new DessertCanvas(this);
            menuCanvas.stop();
            dessertCanvas.stop();
            if (dessertCanvas != null) {
                display.setCurrent(dessertCanvas);
                dessertCanvas.start();
            }
        }
    }

    public void showSnowCanvas() {
        if (CLICKED < 1) {
            CLICKED = CLICKED + 1;
            snowCanvas = new SnowCanvas(this);
            menuCanvas.stop();
            snowCanvas.stop();
            if (snowCanvas != null) {
                display.setCurrent(snowCanvas);
                snowCanvas.start();
            }
        }
    }
}
